01	<%@page import="java.sql.*"%>
02	<%@page import=" java.security.MessageDigest"%>
03	 
04	<html>
05	    <body>
06	 
07	    <%
08	     
09	    String username=request.getParameter("user");
10	    String password=request.getParameter("pass");
11	    String name=request.getParameter("name");
12	    String phone=request.getParameter("phone");
13	    int ph=Integer.parseInt(phone);
14	    byte[] unencodedPassword = password.getBytes();
15	    MessageDigest md = null;
16	 
17	    try {
18	        md = MessageDigest.getInstance("MD5");
19	    } catch (Exception e) {
20	 
21	        //Good practise for error handling by printing the Exception
22	        %>
23	        <%=e%>
24	        <%
25	    }
26	 
27	    //encoding the password
28	 
29	    md.reset();
30	    md.update(unencodedPassword);
31	    byte[] encodedPassword = md.digest();
32	    StringBuffer buf = new StringBuffer();
33	 
34	    for (int i = 0; i < encodedPassword.length; i++) {
35	        if (((int) encodedPassword[i] & 0xff) < 0x10) {
36	            buf.append("0");
37	        }
38	        buf.append(Long.toString((int) encodedPassword[i] & 0xff, 16));
39	    }
40	 
41	    String passw=buf.toString();
42	    Connection con=null;
43	 
44	    //Create a database named "test" and table "details" in mySQL
45	    //user name= root
46	    //password= admin
47	 
48	    try{
49	 
50	    Class.forName("org.gjt.mm.mysql.Driver").newInstance();
51	    con =DriverManager.getConnection("jdbc:mysql:///test","root","admin");
52	    }
53	    catch(Exception e){
54	        %>
55	        <%=e.toString()%>
56	        <%
57	    }
58	 
59	    try{
60	        PreparedStatement ps = con.prepareStatement("INSERT INTO details(user,pass,name,phone) VALUES(?,?,?,?)");
61	        ps.setString(1,username);
62	        ps.setString(2,passw);
63	        ps.setString(3,name);
64	        ps.setInt(4,ph);
65	        int i = ps.executeUpdate();
66	 
67	        ps.close();
68	        con.close();
69	    }
70	    catch(Exception e){
71	 
72	        %>
73	        <%=e.toString()%>
74	        <%
75	    }
76	 
77	        %>  
78	    </body>
79	</html>